package com.jdrx.sw.sewage.api.web;

import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.*;
import com.jdrx.sw.sewage.beans.entity.StationReportAnalysisPO;
import com.jdrx.sw.sewage.beans.vo.DnbSurfaceVO;
import com.jdrx.sw.sewage.beans.vo.ManyDataThresholdVO;
import com.jdrx.sw.sewage.beans.vo.ReportAnalysisVO;
import com.jdrx.sw.sewage.beans.vo.WaterYieldVO;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.StationReportAnalysisServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/dataanalysis")
@Api(value = "数据分析")
public class DataAnalysisApi {
    @Autowired
    private StationReportAnalysisServiceImpl reportAnalysisServiceImpl;

    @ApiOperation(value = "总出水量分析")
    @RequestMapping(value = "selectWaterYield", method = RequestMethod.POST)
    public ResponseVO<List<WaterYieldVO>> selectWaterYield(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                           @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                           @RequestBody DnbThanSurfaceDTO waterYieldQueryDTO) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectWaterYield(waterYieldQueryDTO));
    }

    @ApiOperation(value = "进出水量分析")
    @RequestMapping(value = "selectInAndOutWaterYield", method = RequestMethod.POST)
    public ResponseVO<Map<LocalDateTime, List<ReportAnalysisVO>>> selectInAndOutWaterYield(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                                           @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                                           @RequestBody WaterYieldQueryDTO waterYieldQueryDTO) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectInAndOutWaterYield(waterYieldQueryDTO));
    }

    @ApiOperation(value = "水质-数据分析")
    @RequestMapping(value = "selectWaterQuality", method = RequestMethod.POST)
    public ResponseVO<List<StationReportAnalysisPO>> selectWaterQuality(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                        @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                        @RequestBody WaterQualityQueryDTO waterQualityQueryDTO) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectWaterQuality(waterQualityQueryDTO));
    }


    @ApiOperation(value = "水质分析-修改")
    @RequestMapping(value = "selectWaterQualityUp", method = RequestMethod.POST)
    public ResponseVO selectWaterQualityUp(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                           @RequestHeader(Constant.TENANT_ID) String tenantId,
                                           @RequestBody WaterYieldUpDTO waterYieldUpDTO) {
        reportAnalysisServiceImpl.selectWaterQualityUp(waterYieldUpDTO);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "水质分析-删除")
    @RequestMapping(value = "selectWaterQualityDe", method = RequestMethod.POST)
    public ResponseVO selectWaterQualityDe(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                           @RequestHeader(Constant.TENANT_ID) String tenantId,
                                           @RequestBody WaterYieldUpDTO waterYieldUpDTO) {
        reportAnalysisServiceImpl.selectWaterQualityDe(waterYieldUpDTO);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "能耗分析-数据分析")
    @RequestMapping(value = "selectDnbSurface", method = RequestMethod.POST)
    public ResponseVO<List<ReportAnalysisVO>> selectDnbSurface(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                               @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                               @RequestBody WaterYieldQueryDTO waterYieldQueryDTO) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectDnbSurface(waterYieldQueryDTO));
    }

    @ApiOperation(value = "能耗比-数据分析")
    @RequestMapping(value = "selectDnbThanSurfaceAnalysis", method = RequestMethod.POST)
    public ResponseVO<List<DnbSurfaceVO>> selectDnbThanSurfaceAnalysis(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                       @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                       @RequestBody DnbSurfaceQueryDTO dnbSurfaceQueryDTO) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectDnbThanSurfaceAnalysis(dnbSurfaceQueryDTO));
    }

    @ApiOperation(value = "总能耗比-数据分析")
    @RequestMapping(value = "selectDnbThanSurface", method = RequestMethod.POST)
    public ResponseVO<List<DnbSurfaceVO>> selectDnbThanSurface(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                               @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                               @RequestBody DnbThanSurfaceDTO dnbThanSurfaceDTO) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectDnbThanSurface(dnbThanSurfaceDTO));
    }

    @ApiOperation(value = "数据分析-多数据分析图阈值")
    @RequestMapping(value = "selectManyDataThreshold", method = RequestMethod.POST)
    public ResponseVO<Map<String, List<ManyDataThresholdVO>>> selectManyDataThreshold(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                                      @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                                      @RequestBody @Valid StationIdDTO dto) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectManyDataThreshold(dto));
    }

    @ApiOperation(value = "数据分析-多数据分析图阈值修改")
    @RequestMapping(value = "updateManyDataThreshold", method = RequestMethod.POST)
    public ResponseVO updateManyDataThreshold(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                              @RequestHeader(Constant.TENANT_ID) String tenantId,
                                              @RequestBody @Valid ManyDataThresholdsDTO dto) {
        reportAnalysisServiceImpl.updateManyDataThreshold(dto);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "数据分析-多数据分析图")
    @RequestMapping(value = "selectManyData", method = RequestMethod.POST)
    public ResponseVO<Map<String, Object>> selectManyData(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                          @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                          @RequestBody @Valid manyDataAnalysisQueryDTO dto) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.selectManyData(dto));
    }
}
